package com.chukun.tx.model;

import com.chukun.tx.constants.MessageConstant;
import com.google.gson.Gson;

import java.time.LocalDateTime;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author chukun
 *  消息实体
 */
public class MqMessage {

    private Long messageId;
    private String content;
    private String topic;
    private String tag;
    private Byte status;
    private int haveDeadTimes = -1;
    private Long nextExpireTime = -1L;
    private LocalDateTime createTime;

    public Long getMessageId() {
        return messageId;
    }

    public void setMessageId(Long messageId) {
        this.messageId = messageId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public Byte getStatus() {
        return status;
    }

    public void setStatus(Byte status) {
        this.status = status;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public int getHaveDeadTimes() {
        return haveDeadTimes;
    }

    public void setHaveDeadTimes(int haveDeadTimes) {
        this.haveDeadTimes = haveDeadTimes;
    }

    public Long getNextExpireTime() {
        return nextExpireTime;
    }

    public void setNextExpireTime(Long nextExpireTime) {
        this.nextExpireTime = nextExpireTime;
    }

    public void order2MqMessage(Order order) {
        Gson gson = new Gson();
        this.setContent(gson.toJson(order));
        this.setStatus(MessageConstant.MessageStatus.MESSAGE_CONSUMED.getCode());
    }
}
